<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>

    .item {
        width: 100%;
        height: 30px;
        background-color: #f3f3f3;
        border: 1px solid #666;
        box-sizing: border-box;
    }

    /* 1. 声明过渡效果 */
    .fade-move,
    .fade-enter-active,
    .fade-leave-active {
        transition: all 0.5s cubic-bezier(0.55, 0, 0.1, 1);
    }

    /* 2. 声明进入和离开的状态 */
    .fade-enter-from,
    .fade-leave-to {
        opacity: 0;
        transform: scaleY(0.01) translate(30px, 0);
    }

    /* 3. 确保离开的项目被移除出了布局流
          以便正确地计算移动时的动画效果。 */
    .fade-leave-active {
        position: absolute;
    }

</style>
<!--
   列表过渡  https://cn.vuejs.org/guide/built-ins/transition-group.html
   使用的是标签  <TransitionGroup></TransitionGroup>
-->
<body>
<div id="app"></div>
</body>
<script src="js/vue.js"></script>
<script>
    const app = Vue.createApp({
        data() {
            return {
                msg: "列表过渡动画",
                list: ['Tim', 'Jim', 'Tom', 'Ben', 'Jack', 'John', 'Nike'],
            }
        },
        methods: {
            add(){
                this.list.push("add-"+ this.list.length)
            },
            del(){
                this.list.pop();
            }
        },
        template: `
          <div>

          <!--     这里 tag="ul" 表示展示样式类似于 ul 标签展示   -->
            <transition-group tag="ul" name="fade">
              <div  v-for="item in list" :key="item">{{ item }}</div>
            </transition-group>

            <div>
              <button @click="add">增加</button>
              <button @click="del">删除</button>
            </div>
          </div>
        `

    }).mount("#app");
</script>

</html>
